﻿using System;
using System.Runtime.CompilerServices;
using UnityEngine;

public static class StringExtension
{
    public static bool ContainsIgnoreCase(this string a, string b)
    {
        return a.ToLower().Contains(b.ToLower());
    }

    public static bool EndsWithIgnoreCase(this string s, string other)
    {
        return s.ToLower().EndsWith(other.ToLower());
    }

    public static bool EqualsIgnoreCase(this string a, string b)
    {
        return (a.ToUpper() == b.ToUpper());
    }

    public static string Lerp(this string text, float time)
    {
        return text.Lerp(0, text.Length, time);
    }

    public static string Lerp(this string text, int startIndex, int endIndex, float time)
    {
        endIndex = Mathf.Clamp(endIndex, 0, text.Length);
        startIndex = Mathf.Clamp(startIndex, 0, endIndex);
        int num = startIndex.Lerp(endIndex, time);
        if (startIndex <= endIndex)
        {
            return text.Substring(startIndex, num - startIndex);
        }
        return text.Substring(num, startIndex - num);
    }

    public static bool StartsWithIgnoreCase(this string s, string other)
    {
        return s.ToLower().StartsWith(other.ToLower());
    }

    public static string ToProperCase(this string the_string)
    {
        if (the_string == null)
        {
            return the_string;
        }
        if (the_string.Length < 2)
        {
            return the_string.ToUpper();
        }
        string str = the_string.Substring(0, 1).ToUpper();
        for (int i = 1; i < the_string.Length; i++)
        {
            if (char.IsUpper(the_string[i]))
            {
                str = str + " ";
            }
            str = str + the_string[i];
        }
        return str;
    }
}

